/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package logbook.ui;

import com.jgoodies.looks.plastic.PlasticLookAndFeel;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import layout.TableLayout;

/**
 *
 * @author Ejaz
 */
public class LogBookApp extends JFrame {

  private JFrame self;
  // ---------------------------------------------------------------------------
  private JPanel mainPanel;
  private JPanel cardPanel;
  private JPanel keysPanel;
  private JPanel logsPanel;
  private JPanel adedPanel;
  // ---------------------------------------------------------------------------
  private JPanel keysNavPanel;
  private JPanel logsNavPanel;
  private JPanel adedNavPanel;
  // ---------------------------------------------------------------------------
  private JButton keysNavMovLogButton;
  private JButton keysNavAddLogButton;
  private JButton keysNavSaveLogButton;
  private JButton keysNavDelLogButton;
  private JButton keysNavNextLogButton;
  // ---------------------------------------------------------------------------
  private JButton logsNavAddLogButton;
  private JButton logsNavEditLogButton;
  private JButton logsNavDelLogButton;
  private JButton logsNavBackLogButton;
  // ---------------------------------------------------------------------------
  private JButton adedNavClearLogButton;
  private JButton adedNavSaveLogButton;
  private JButton adedNavBackLogButton;
  // ---------------------------------------------------------------------------
  private JList keysList;
  private JTextField keySearch;
  private JList keys;
  private CardLayout cl;
  private LogsTableModel ltModel;
  private JTextField adedLogId;
  private JTextField adedDate;
  private JTextArea adedNotes;
  // ---------------------------------------------------------------------------
  private final String VIEW_KEYS = "view_keys";
  private final String VIEW_LOGS = "view_logs";
  private final String ADED_LOGS = "aded_logs";
  // ---------------------------------------------------------------------------
  private Connection conn = null;
  private Statement stmt = null;
  // ---------------------------------------------------------------------------
  private JTable logsTable;
  private JTextArea logsDetail;

  static {
    try {
      Class.forName("org.sqlite.JDBC");
    } catch (Exception e) {
    }
  }

  private String escape(String data) {
    // System.out.println("Escaped data: " + data.replace("'", "\\''"));
    return data.replace("'", "\''");
  }

  private static void setUIFont(javax.swing.plaf.FontUIResource f) {
    java.util.Enumeration keys = UIManager.getDefaults().keys();
    while (keys.hasMoreElements()) {
      Object key = keys.nextElement();
      Object value = UIManager.get(key);
      if (value instanceof javax.swing.plaf.FontUIResource) {
        UIManager.put(key, f);
      }
    }
  }

  public LogBookApp(String database) throws Exception {
    super("LogBook");
    self = this;

    setUIFont(new javax.swing.plaf.FontUIResource(new Font("Consolas", Font.PLAIN, 14)));
    conn = DriverManager.getConnection(database);
    stmt = conn.createStatement();

    stmt.executeUpdate("CREATE TABLE IF NOT EXISTS keys ("
            + "id integer primary key, "
            + "key text not null)");
    stmt.executeUpdate("CREATE TABLE IF NOT EXISTS entry ("
            + "id integer primary key, "
            + "kid integer not null, "
            + "entry_date text not null,"
            + "notes text not null,"
            + "foreign key (kid) references keys(id))");
    stmt.executeUpdate("CREATE INDEX IF NOT EXISTS entry_entry_date on entry(entry_date)");
    stmt.executeUpdate("CREATE INDEX IF NOT EXISTS entry_kid on entry(kid)");
    stmt.executeUpdate("CREATE INDEX IF NOT EXISTS entry_notes on entry(notes)");
    stmt.executeUpdate("CREATE INDEX IF NOT EXISTS keys_key on keys(key)");
    
    initUI();
    addListeners();
  }

  private void initUI() {
    mainPanel = new JPanel();

    this.getContentPane().setLayout(new BorderLayout());
    this.getContentPane().add(mainPanel, BorderLayout.CENTER);

    JPanel tmp1 = new JPanel();
    tmp1.setLayout(new BorderLayout());
    keySearch = new JTextField();
    keySearch.setFont(new Font("Consolas", Font.PLAIN, 16));
    tmp1.add(keySearch, BorderLayout.CENTER);
    tmp1.setBorder(BorderFactory.createTitledBorder("Key Search"));

    mainPanel.setLayout(new BorderLayout(4, 4));
    mainPanel.setBorder(new EmptyBorder(7, 7, 7, 7));
    mainPanel.add(tmp1, BorderLayout.NORTH);

    cl = new CardLayout();

    cardPanel = new JPanel(cl);

    keysPanel = new JPanel();
    keysPanel.setBorder(BorderFactory.createTitledBorder("Key Management"));

    logsPanel = new JPanel();
    logsPanel.setBorder(BorderFactory.createTitledBorder("Log Management"));

    adedPanel = new JPanel();
    adedPanel.setBorder(BorderFactory.createTitledBorder("Add/Edit Log"));


    cardPanel.add(keysPanel, VIEW_KEYS);
    cardPanel.add(logsPanel, VIEW_LOGS);
    cardPanel.add(adedPanel, ADED_LOGS);

    // Keys Panel --------------------------------------------------------------
    keysList = new JList(new String[]{});
    keysList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    keysList.setVisibleRowCount(-1);
    keysPanel.setLayout(new BorderLayout(0, 0));
    keysPanel.add(new JScrollPane(keysList), BorderLayout.CENTER);
    keysNavPanel = new JPanel();
    double size[][] = {{0.25, 0.75}, {TableLayout.FILL}};
    keysNavPanel.setLayout(new TableLayout(size));
    JPanel keysNavLeft = new JPanel();
    JPanel keysNavRight = new JPanel();
    keysNavLeft.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 1));
    keysNavRight.setLayout(new FlowLayout(FlowLayout.RIGHT, 2, 1));
    keysNavPanel.add(keysNavLeft, "0, 0");
    keysNavPanel.add(keysNavRight, "1, 0");
    keysNavMovLogButton = new JButton("Move");
    keysNavMovLogButton.setEnabled(false);
    keysNavRight.add(keysNavMovLogButton);
    keysNavAddLogButton = new JButton("Add");
    keysNavAddLogButton.setEnabled(false);
    keysNavRight.add(keysNavAddLogButton);
    keysNavSaveLogButton = new JButton("Edit");
    keysNavSaveLogButton.setEnabled(false);
    keysNavRight.add(keysNavSaveLogButton);
    keysNavDelLogButton = new JButton("Del");
    keysNavDelLogButton.setEnabled(false);
    keysNavRight.add(keysNavDelLogButton);
    keysNavNextLogButton = new JButton("Next");
    keysNavNextLogButton.setEnabled(false);
    keysNavLeft.add(keysNavNextLogButton);
    keysPanel.add(keysNavPanel, BorderLayout.SOUTH);

    // View Logs Panel ---------------------------------------------------------
    this.ltModel = new LogsTableModel(stmt);
    logsTable = new JTable(ltModel);
    logsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    logsDetail = new JTextArea();
    logsDetail.setEditable(false);
    logsDetail.setLineWrap(true);
    logsDetail.setWrapStyleWord(true);
    logsTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    JSplitPane splitter = new JSplitPane();
    splitter.setOrientation(JSplitPane.VERTICAL_SPLIT);
    splitter.setTopComponent(new JScrollPane(logsTable));
    splitter.setBottomComponent(new JScrollPane(logsDetail));
    splitter.setOneTouchExpandable(false);
    splitter.setDividerSize(5);
    splitter.setDividerLocation(250);
    logsPanel.setLayout(new BorderLayout(0, 0));
    logsPanel.add(splitter, BorderLayout.CENTER);
    logsNavPanel = new JPanel();
    double size2[][] = {{TableLayout.MINIMUM, TableLayout.FILL}, {TableLayout.FILL}};
    logsNavPanel.setLayout(new TableLayout(size2));
    JPanel logsNavLeft = new JPanel();
    JPanel logsNavRight = new JPanel();
    logsNavLeft.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 1));
    logsNavRight.setLayout(new FlowLayout(FlowLayout.RIGHT, 2, 1));
    logsNavPanel.add(logsNavLeft, "0, 0");
    logsNavPanel.add(logsNavRight, "1, 0");
    logsNavAddLogButton = new JButton("Add");
    // logsNavAddLogButton.setEnabled(false);
    logsNavRight.add(logsNavAddLogButton);
    logsNavEditLogButton = new JButton("Edit");
    logsNavEditLogButton.setEnabled(false);
    logsNavRight.add(logsNavEditLogButton);
    logsNavDelLogButton = new JButton("Del");
    logsNavDelLogButton.setEnabled(false);
    logsNavRight.add(logsNavDelLogButton);
    logsNavBackLogButton = new JButton("Back");
    logsNavBackLogButton.setEnabled(true);
    logsNavLeft.add(logsNavBackLogButton);

    logsPanel.add(logsNavPanel, BorderLayout.SOUTH);

    // Add/Edit Log Panel ------------------------------------------------------
    adedPanel.setLayout(new BorderLayout(0, 0));
    JPanel tmp3 = new JPanel();
    GridBagLayout gl = new GridBagLayout();
    tmp3.setLayout(gl);
    GridBagConstraints gc = null;

    gc = new GridBagConstraints();
    gc.gridx = 0;
    gc.gridy = 0;
    gc.anchor = GridBagConstraints.NORTHWEST;
    gc.insets = new Insets(0, 0, 3, 0);
    tmp3.add(new JLabel("LogId: ", JLabel.LEFT), gc);

    gc = new GridBagConstraints();
    gc.gridx = 1;
    gc.gridy = 0;
    gc.weightx = 1.0;
    gc.fill = GridBagConstraints.HORIZONTAL;
    gc.insets = new Insets(0, 3, 3, 0);
    adedLogId = new JTextField();
    adedLogId.setEditable(false);
    tmp3.add(adedLogId, gc);

    gc = new GridBagConstraints();
    gc.gridx = 0;
    gc.gridy = 1;
    gc.anchor = GridBagConstraints.NORTHWEST;
    gc.insets = new Insets(0, 0, 3, 0);
    tmp3.add(new JLabel("Date: ", JLabel.LEFT), gc);

    gc = new GridBagConstraints();
    gc.gridx = 1;
    gc.gridy = 1;
    gc.weightx = 1.0;
    gc.fill = GridBagConstraints.HORIZONTAL;
    gc.insets = new Insets(0, 3, 3, 0);
    adedDate = new JTextField();
    tmp3.add(adedDate, gc);

    gc = new GridBagConstraints();
    gc.gridx = 0;
    gc.gridy = 2;
    gc.gridwidth = 2;
    gc.weightx = 1.0;
    gc.weighty = 1.0;
    gc.insets = new Insets(0, 3, 3, 0);
    gc.fill = GridBagConstraints.BOTH;
    adedNotes = new JTextArea();
    adedNotes.setLineWrap(true);
    adedNotes.setWrapStyleWord(true);
    tmp3.add(new JScrollPane(adedNotes), gc);

    adedPanel.add(tmp3, BorderLayout.CENTER);

    adedNavPanel = new JPanel();
    adedNavPanel.setLayout(new TableLayout(size2));
    JPanel adedNavLeft = new JPanel();
    JPanel adedNavRight = new JPanel();
    adedNavPanel.add(adedNavLeft, "0, 0");
    adedNavPanel.add(adedNavRight, "1, 0");
    adedNavLeft.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 1));
    adedNavRight.setLayout(new FlowLayout(FlowLayout.RIGHT, 2, 1));

    adedNavClearLogButton = new JButton("Clear");
    // adedNavClearLogButton.setEnabled(false);
    adedNavRight.add(adedNavClearLogButton);

    adedNavSaveLogButton = new JButton("Save");
    adedNavSaveLogButton.setEnabled(true);
    adedNavRight.add(adedNavSaveLogButton);

    adedNavBackLogButton = new JButton("Back");
    adedNavBackLogButton.setEnabled(true);
    adedNavLeft.add(adedNavBackLogButton);

    adedPanel.add(adedNavPanel, BorderLayout.SOUTH);

    cl.show(cardPanel, VIEW_KEYS);
    mainPanel.add(cardPanel, BorderLayout.CENTER);

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setSize(400, 500);
  }

  public void showMatchingKeys() {
    cl.show(cardPanel, VIEW_KEYS);
    String keyText = keySearch.getText();
    // System.out.println("Len: " + keyText.trim().length());

    keysNavAddLogButton.setEnabled(false);
    keysList.removeAll();
    keysList.setListData(new ArrayList().toArray());

    if (keyText.trim().length() > 2) {
      // clear keysList
      // populate keysList
      ResultSet rs = null;
      try {
        rs = stmt.executeQuery("select key from keys "
                + "where key like '%" + keyText.trim() + "%'");
        List list = new ArrayList();
        while (rs.next()) {
          list.add(rs.getString(1));
        }
        keysNavAddLogButton.setEnabled(true);
        keysList.setListData(list.toArray());
      } catch (Exception x) {
        x.printStackTrace(System.err);
      } finally {
        try {
          rs.close();
        } catch (Exception x2) {
        }
      }
    }
  }

  private void addListeners() {
    keySearch.addKeyListener(new KeyAdapter() {

      @Override
      public void keyReleased(KeyEvent e) {
        // System.out.println("Key: " + e.getKeyCode());
        cl.show(cardPanel, VIEW_KEYS);
        if (e.getKeyCode() == KeyEvent.VK_DOWN && keysList.getModel().getSize() > 0) {
          keysList.setSelectedIndex(0);
          keysList.requestFocus();
          keysList.requestFocusInWindow();
          return;
        }

        showMatchingKeys();
      }
    });

    keysList.addListSelectionListener(new ListSelectionListener() {

      @Override
      public void valueChanged(ListSelectionEvent e) {
        int count = keysList.getSelectedIndex();
        if (count != -1) {
          keySearch.setText(keysList.getSelectedValue().toString());
          keysNavMovLogButton.setEnabled(true);
          keysNavSaveLogButton.setEnabled(true);
          keysNavDelLogButton.setEnabled(true);
          keysNavAddLogButton.setEnabled(false);
          keysNavNextLogButton.setEnabled(true);
        } else {
          // keySearch.setText("");
          keysNavMovLogButton.setEnabled(false);
          keysNavSaveLogButton.setEnabled(false);
          keysNavDelLogButton.setEnabled(false);
          keysNavNextLogButton.setEnabled(false);
          if (keySearch.getText().trim().length() > 2) {
            keysNavAddLogButton.setEnabled(true);
          }
        }
      }
    });

    keysNavMovLogButton.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        String oldKey = keySearch.getText().trim();
        if (oldKey != null && oldKey.length() > 0) {
          ResultSet rs = null;

          try {
            oldKey = escape(oldKey); // newKey.replace("'", "''");
            int oldKid = -1;
            rs = stmt.executeQuery("select id from keys where key = '" + oldKey + "'");
            while (rs.next()) {
              oldKid = rs.getInt(1);
            }
            rs.close();

            if (oldKid == -1) {
              return;
            }

            List data = new ArrayList();
            rs = stmt.executeQuery("select key from keys order by key");
            while (rs.next()) {
              data.add(rs.getString(1));
            }
            rs.close();

            Object[] array = data.toArray();
            Object newKey =
                    JOptionPane.showInputDialog(
                    self,
                    "Select new key",
                    oldKey,
                    JOptionPane.QUESTION_MESSAGE,
                    null,
                    array,
                    array[0]);
            if (newKey != null) {
              int newKid = -1;
              rs = stmt.executeQuery("select id from keys where key = '" + escape(newKey.toString()) + "'");
              while (rs.next()) {
                newKid = rs.getInt(1);
              }
              rs.close();
              if (newKid != -1) {
                int count = stmt.executeUpdate("update entry set kid = " + newKid + " where kid = " + oldKid);
                System.out.println("# keys updated: " + count);
                count = stmt.executeUpdate("delete from keys where id = " + oldKid);
                System.out.println("# keys deleted: " + count);
              }
            }
            keySearch.setText("");
          } catch (Exception x) {
            x.printStackTrace(System.err);
          }
        }
      }
    });

    keysNavAddLogButton.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        String newKey = keySearch.getText().trim();
        if (newKey != null && newKey.length() > 0) {
          try {
            newKey = escape(newKey); // newKey.replace("'", "''");
            int count = stmt.executeUpdate("insert into keys (id, key) values (null, '" + newKey + "')");
            System.out.println("# keys inserted: " + count);
            showMatchingKeys();
          } catch (Exception x) {
            x.printStackTrace(System.err);
          }
        }
      }
    });

    keysNavSaveLogButton.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        String oldKey = keysList.getSelectedValue().toString();
        String newKey = JOptionPane.showInputDialog(self, "New Key?");
        if (newKey != null) {
          try {
            oldKey = escape(oldKey); // oldKey.replace("'", "''");
            newKey = escape(newKey); // newKey.replace("'", "''");
            int count = stmt.executeUpdate("update keys set key = '" + newKey + "' where key = '" + oldKey + "'");
            System.out.println("# keys updated: " + count);
            keySearch.setText(newKey);
            showMatchingKeys();
          } catch (Exception x) {
            x.printStackTrace(System.err);
          }
        }
      }
    });

    keysNavDelLogButton.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        String key = keySearch.getText();
        if (key != null) {
          try {
            key = escape(key); // key.replace("'", "''");
            int count = stmt.executeUpdate("delete from keys where key = '" + key + "'");
            System.out.println("# keys updated: " + count);
            keySearch.setText("");
            showMatchingKeys();
          } catch (Exception x) {
            x.printStackTrace(System.err);
          }
        }
      }
    });

    keysNavNextLogButton.getInputMap().put(KeyStroke.getKeyStroke("ALT N"),
            new AbstractAction() {

              public void actionPerformed(ActionEvent e) {
                System.out.println("ALT N pressed!");
              }
            });

    keysNavNextLogButton.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        logsDetail.setText("");
        keySearch.setEditable(false);
        ltModel.refreshData(keysList.getSelectedValue().toString());
        cl.show(cardPanel, VIEW_LOGS);
        logsTable.requestFocus();
      }
    });

    logsNavBackLogButton.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        keySearch.setEditable(true);
        cl.show(cardPanel, VIEW_KEYS);
      }
    });

    logsNavAddLogButton.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        keySearch.setEditable(false);
        adedLogId.setText("");
        adedDate.setText("");
        adedNotes.setText("");
        cl.show(cardPanel, ADED_LOGS);
        adedDate.requestFocus();
      }
    });

    adedDate.addFocusListener(new FocusAdapter() {

      @Override
      public void focusGained(FocusEvent e) {
        if (adedDate.getText().trim().length() == 0) {
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
          adedDate.setText(sdf.format(new Date()));
        }
        super.focusGained(e);
      }
    });
    adedNavBackLogButton.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        keySearch.setEditable(false);
        cl.show(cardPanel, VIEW_LOGS);
        logsTable.requestFocus();
      }
    });

    adedNavSaveLogButton.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        try {
          String lid = adedLogId.getText().trim();
          String key = escape(keySearch.getText().trim());
          String log = escape(adedNotes.getText().trim());

          // System.out.println("log: " + log);

          if (lid == null || lid.length() == 0) {
            // insert
            stmt.executeUpdate("insert into entry ("
                    + "id, kid, entry_date, notes) values ("
                    + "null, ("
                    + "select id from keys where key = '"
                    + key + "'"
                    + "), '"
                    + adedDate.getText()
                    + "','"
                    + log
                    + "')");
          } else {
            // update
            stmt.executeUpdate("update entry set entry_date = '"
                    + escape(adedDate.getText().trim()) + "', "
                    + "notes = '"
                    + escape(adedNotes.getText().trim()) + "' "
                    + "where id = " + adedLogId.getText());
          }
          adedLogId.setText("");
          adedDate.setText("");
          adedNotes.setText("");
          ltModel.refreshData(key);
          cl.show(cardPanel, VIEW_LOGS);
          logsTable.requestFocus();
        } catch (Exception x) {
          x.printStackTrace(System.err);
        }
      }
    });

    adedNavClearLogButton.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        adedDate.setText("");
        adedNotes.setText("");
      }
    });

    logsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

      @Override
      public void valueChanged(ListSelectionEvent e) {
        StringBuilder selectedData = new StringBuilder();

        int[] selectedRow = logsTable.getSelectedRows();
        // int[] selectedColumns = logsTable.getSelectedColumns();

        logsNavEditLogButton.setEnabled(false);
        logsNavDelLogButton.setEnabled(false);
        for (int i = 0; i < selectedRow.length; i++) {
          logsNavEditLogButton.setEnabled(true);
          logsNavDelLogButton.setEnabled(true);
          selectedData.append(logsTable.getValueAt(selectedRow[i], 2)).append("\n");
        }

        logsDetail.setText(selectedData.toString());
      }
    });

    logsNavDelLogButton.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        int[] selectedRow = logsTable.getSelectedRows();

        for (int i = 0; i < selectedRow.length; i++) {
          ResultSet rs = null;
          try {
            int logId = Integer.parseInt(logsTable.getValueAt(selectedRow[i], 0).toString());
            stmt.executeUpdate("delete from entry where id = " + logId);

            logsDetail.setText("");
            keySearch.setEditable(false);
            ltModel.refreshData(keysList.getSelectedValue().toString());
          } catch (Exception x) {
            x.printStackTrace(System.err);
          } finally {
            try {
              rs.close();
            } catch (Exception x2) {
            }
          }
        }
      }
    });

    logsNavEditLogButton.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
        int[] selectedRow = logsTable.getSelectedRows();

        for (int i = 0; i < selectedRow.length; i++) {
          ResultSet rs = null;
          try {
            int logId = Integer.parseInt(logsTable.getValueAt(selectedRow[i], 0).toString());
            rs = stmt.executeQuery("select entry_date, notes from entry where id = " + logId);
            while (rs.next()) {
              adedLogId.setText("" + logId);
              adedDate.setText(rs.getString(1));
              adedNotes.setText(rs.getString(2));
            }
            break;
          } catch (Exception x) {
            x.printStackTrace(System.err);
          } finally {
            try {
              rs.close();
            } catch (Exception x2) {
            }
          }
        }

        cl.show(cardPanel, ADED_LOGS);
        adedDate.requestFocus();
      }
    });
  }

  /**
   * Entry Point
   */
  public static void main(String[] args) throws Exception {
    if (args.length == 0) {
      System.err.println("ERROR: Please specify the logbook location");
      System.err.println("usage: java logbook.LogBookApp <logbook location>");
      System.exit(1);
    }

    try {
      UIManager.setLookAndFeel(new PlasticLookAndFeel());
    } catch (Exception e) {
    }
    LogBookApp lba = new LogBookApp("jdbc:sqlite:" + args[0]); // c:/data/logbook.db"
    lba.setVisible(true);
  }
}
